# middleware.py
from django.utils.deprecation import MiddlewareMixin
from .models import PageView


class PageViewMiddleware(MiddlewareMixin):
    def process_request(self, request):
        url = request.path
        page_view, created = PageView.objects.get_or_create(url=url)
        page_view.count += 1
        page_view.save()
